home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-01 | 4.0 KB | 136 lines | [TEXT/KAHL] |
- ===========
- Description
- -----------
-
- Patch Library is used to manage patches to traps. Installing and removing
- patches is simpler than using the Toolbox routines NSetTrapAddress and
- NGetTrapAddress. In addition, macros are provided that setup and restore
- the environment for the patch routine. Patch Library is not as useful
- for native PowerPC software as it is for 68K software, and for software
- that must avoid tail patches. Complete C source code and a THINK C 7.0
- project are provided.
-
- (c) Copyright 1994 Ari Halberstadt. See the file Distribution for
- distribution terms.
-
- ============================
- What is in this Distribution
- ----------------------------
-
- :Documentation:Distribution
- Distribution policy, copyright notice, my address
-
- :Documentation:README
- This document
-
- :Documentation:Version History
- Documents the changes made to each version of Patch Library
-
- :Executables:
- Contains an executable M68K binary for testing the patch
- library.
-
- :Source:PatchLib
- Folder containing the source code for Patch Library
-
- :Source:PatchTest
- Folder containing the source code for a simple application
- that demonstrates Patch Library.
-
- ===================
- Using Patch Library
- -------------------
-
- Patch Library is used to manage patches to traps. You can create as many
- patches as you like. Each patch is created as a non-relocatable block in
- the heap. Under Finder (but not MultiFinder) you must remove all patches
- before exiting the application. All patches are tracked in a linked-list
- of patches, so that you can easily remove all of the patches when
- exiting.
-
- The patch function must be declared with the same prototype as the
- trap that it is patching. The parameters that are passed to the function
- are the same parameters on the stack that were passed in the call to
- the trap. This allows you to change the values of the parameters before
- you call the original trap routine. You should call PATCH_ENTER at the
- start of your patch function, and call PATCH_RETURN at the end of your
- patch function. The PATCH_ENTER macro saves registers d0-d7/a0-a7 and
- sets up register a5. The PATCH_RETURN macro restores all saved registers
- and calls the address of the original trap routine. Both macros are no-ops
- in PowerPC code.
-
- You can temporarily remove the patch with PatchRemove and reinstall it with
- PatchInstall. To permanently remove the patch and dispose of the memory it
- occupies call PatchEnd.
-
- This library is meant to be used with an application. It could be modified
- to work with a system extension, but you would have to allocate the
- patches with NewPtrSysClear instead of NewPtrClear. Additional changes
- might also be needed.
-
- ====================
- Functional Interface
- --------------------
-
- void PatchInstall(PatchType patch)
-
- * PatchInstall installs a patch.
-
- void PatchRemove(PatchType patch)
-
- * PatchRemove removes a patch.
-
- void PatchRemoveAll(void)
-
- * PatchRemoveAll removes all patches.
-
- PatchType PatchBegin(void *addr, short num)
-
- * PatchBegin creates and installs a patch, and returns a pointer to the
- patch structure, or NULL if the patch could not be created.
-
- void PatchEnd(PatchType patch)
-
- * PatchEnd removes and disposes of the patch.
-
- void PatchEndAll(void)
-
- * PatchEndAll removes and disposes of all patches.
-
- ========
- EXAMPLES
- --------
-
- See the file PatchTest.c for a simple, yet complete, example of how
- to use Patch Library.
-
- ========================
- Native (and Fat) Patches
- ------------------------
-
- Patch Library is primarily useful for writing non-native trap patches.
- You should generally use fat code (M68K and PPC) for all of your
- patches. I have not yet written a fat patch. You should not patch
- selector-based routines since Apple provides no documented method
- for doing so using PPC patches.
-
- =======
- PORTING
- -------
-
- This library was developed using THINK C 5.0.4 and 7.0. The C code should be
- portable to other compilers, and has been used successfully compiled with
- CodeWarrior DR4.
-
- ==============
- Known Problems
- --------------
-
- There are no known problems.
-
- =======
- Credits
- -------
-
- Suggest something and have your name placed here! :-)
-